<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
cfc('core')->checklogin();
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
$return=array();
if($_RQ['op']=='get'){
	$return['item']=$this->model('member')->getdetail();
	exi($return);
}
if($_RQ['op']=='recharge'){
	$post=get_postdata();
	if(intval($post['money'])<=0){
		exi('请先设置充值金额！并且为整数！','error');
	}
	$fee=sprintf("%.2f", intval($post['money']));
	$data=array(
		'uniacid'=>$_SESSION['uniacid'],
		'mid'=>$_SESSION['uid'],
		'couponid'=>intval($post['couponid']),
		'fee'=>$fee,
		'createtime'=>TIMESTAMP
	);
	pdo_insert('core_recharge',$data);
	$id=pdo_insertid();
	$params=array(
		'action'=>'recharge',
		'id'=>$id,
		'fee'=>$fee,
		'title'=>'倍财金充值',
		'plugin'=>'jy_pinggou',
		'pay_type'=>'wechat',
		'no_type'=>array('hdfk'),
		'back_url'=>'jy_pinggou/recharge/pay_result/',
		'success_url'=>'core/member.log/',
		'error_url'=>'core/member.log/',
	);
	$pay_id=cfc('pay')->create_pay_order($params);
	exi($pay_id);
}
if($_RQ['op']=='pay_result'){
	$payresult=$_SESSION['pay_result'];
	$recharge=pdo_get('core_recharge',array('id'=>$payresult['id'],'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),array('id','fee','status','couponid'));
	if($recharge['fee']!=$payresult['fee']){
		exi('支付失败，支付金额不匹配！','error');
	}
	if($recharge['status']){
		exi('该订单已支付！无需重复支付！','error');
	}
	if($payresult['status']!=1){
		exi('充值失败！','error');
	}
	pdo_update('core_recharge',array('status'=>1,'pay_type'=>$payresult['pay_type']),array('id'=>$recharge['id'],'uniacid'=>$_SESSION['uniacid']));
	$this->model('member')->recharge($_SESSION['uid'],$recharge['fee'],0,'充值倍财金');
	exi('充值成功！');
}